package com.fuqi.android.zhongcai.base.view.activity;

import android.util.Log;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.request.api.TrainReadCountApi;
import com.fuqi.android.zhongcai.base.request.result.TrainListResult;
import com.fuqi.android.zhongcai.base.request.result.TrainReadCountResult;
import com.fuqi.framework.gson.GsonHelper;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;
import com.zzhoujay.richtext.RichText;

import butterknife.Bind;

public class TrainingDetailActivity extends BaseActivity {


    @Bind(R.id.tv_train_title)
    TextView tvTrainTitle;
    @Bind(R.id.tv_train_date)
    TextView tvTrainDate;
    @Bind(R.id.tv_train_count)
    TextView tvTrainCount;
    @Bind(R.id.tv_train_content)
    TextView tvTrainContent;

    private TrainListResult trainListResult;

    @Override
    public void initView() {



    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

        titleBar.setTitle("培训交流");
        trainListResult = GsonHelper.getDeserializer().fromJson(getIntent().getStringExtra("data"), TrainListResult.class);

        if (trainListResult != null){
            tvTrainTitle.setText(trainListResult.getTitle());
            tvTrainDate.setText(trainListResult.getUpdateDate());
            tvTrainCount.setText("浏览量: " + trainListResult.getReadCount());
            RichText.from(trainListResult.getContent()).async(true).into(tvTrainContent);
        }


        RequestManager.getInstance().call(new TrainReadCountApi(new TrainReadCountApi.TrainReadCountParams(trainListResult.getTrainId()),

                respTrainReadCountListener, errorListener));

    }


    Response.Listener<TrainReadCountResult> respTrainReadCountListener = new Response.Listener<TrainReadCountResult>() {

        @Override
        public void onResponse(TrainReadCountResult response) {

            if (HandleCode.requestSuccess()) {



                Log.i("juner", "juner response TrainReadCountResult: " + GsonHelper.writeValue(response));
            } else {



            }
        }
    };


    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };

    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_training_detail;
    }


}
